<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>待办事项</title>
</head>
<body>
    <div class="nav">
        <input type="text">
        <button>新建任务</button>
    </div>

    <div class="container">
        <div class="todo">
            <h3>未完成</h3>
        </div>

        <div class="done">
            <h3>已完成</h3>
        </div>

    </div>

    <script>
        let addTaskButton = document.querySelector('.nav button');
        addTaskButton.onclick = function(){
            let input = document.querySelector('.nav input');
            let taskContent = input.value;
            if(taskContent==''){
                console.log();
                return;
            }
            let row = document.createElement('div');
            row.className = 'row';
            let checkbox = document.createElement('input');
            checkbox.type = 'checkbox';
            let span = document.createElement('span');
            span.innerHTML = taskContent;
            let button = document.createElement('button');
            button.innerHTML = '删除';
            row.appendChild(checkbox);
            row.appendChild(span);
            row.appendChild(button);
            let todo = document.querySelector('.todo');
            todo.appendChild(row);
            input.value='';

            checkbox.onclick = function(){
                if(checkbox.checked){
                    let target = document.querySelector('.done');
                    target.appendChild(row);
                }else{
                    let target = document.querySelector('.todo');
                    target.appendChild(row);
                }
            }
            button.onclick = function(){
                let parent = row.parentNode;
                parent.removeChild(row);
            }
        }
    </script>

    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .nav{
            /* background-color: red; */
            width: 800px;
            height: 100px;
            margin: 0 auto;
            display: flex;
            align-items: center;
        }

        .nav input{
            height: 50px;
            width: 600px;
        }

        .nav button{
            height: 50px;
            width: 200px;
            background-color:orange;
            color: white;
            border: none;
        }

        .container{
            /* background-color: orange; */
            width: 800px;
            height: 800px;
            margin: 0 auto;
            display: flex;
        }
        .container h3{
            height: 50px;
            text-align: center;
            line-height: 50px;
            background-color: #333;
            color: rgb(253, 253, 253);
        }
        .todo{
            /* background-color: green; */
            width: 50%;
            height:100% ;
        }
        
        .done{
            /* background-color:blue; */
            width: 50%;
            height: 100%; 
        }
        .row{
            height: 50px;
            display:flex;
            align-items: center;
        }
        .row input{
            margin: 0 10px;
        }
        .row span{
            width: 300px;
        }
        .row button{
            width: 50px;
            height: 40px;
        }
    </style>
</body>
</html>